package com.yang.controller.wx;

import com.yang.bean.MarketComment;
import com.yang.bean.MarketUser;
import com.yang.bean.common.BaseRespVo;
import com.yang.bean.common.CommonData;
import com.yang.bean.yvo.wx.CommentCountVo;
import com.yang.bean.yvo.wx.CommentLIstBO;
import com.yang.service.wx.WXCommentService;
import com.yang.utils.UserUtil;
import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author: 杨庆
 * @since: 2022.9.12 16:28
 * @description:
 */

@RestController
@RequestMapping("wx/comment/")
public class WXCommentController {

    @Autowired
    WXCommentService wxCommentService;

    @RequestMapping("list")
    public BaseRespVo list(CommentLIstBO commentLIstBO) {
       CommonData commonData =  wxCommentService.selectList(commentLIstBO);
        return BaseRespVo.ok(commonData);
    }

    @RequestMapping("count")
    public BaseRespVo count(Integer valueId, Integer type) {
        CommentCountVo data = wxCommentService.count(valueId, type);
        return BaseRespVo.ok(data);
    }


    @Autowired
    DefaultWebSessionManager defaultWebSessionManager;
    @RequestMapping("post")
    public BaseRespVo post(@RequestBody MarketComment marketComment, HttpServletRequest request) {
        MarketUser userMsg = UserUtil.getUserMsg(request, defaultWebSessionManager);

        MarketComment marketComment1 =  wxCommentService.postComment(marketComment,userMsg);
        return BaseRespVo.ok(marketComment1);
    }


}
